import * as api from '.';

const taskApi = {

  find: async (id: string) => {
    return api.GET('/api/task/find/:id', { id }, null);
  },

  details: async (taskId: string, startDate: string, endDate: string, executeStatus: string, reverseOrder: boolean, pageNumber: number, pageSize: number) => {
    const data = {
      startDate,
      endDate,
      executeStatus,
      reverseOrder,
      pageNumber,
      pageSize
    };
    return api.GET('/api/task/details/:taskId', { taskId }, data);
  },

  query: async (keyword: string, companyId: string, appType: string, active: string, frequency: string, lastExecuteStatus: string,
    pageNumber: number, pageSize: number) => {
    const data = {
      keyword,
      companyId,
      appType,
      active,
      frequency,
      lastExecuteStatus,
      pageNumber,
      pageSize
    };
    return api.GET('/api/task/query', null, data);
  },

  save: async (data: any) => {
    return api.POST('/api/task/save', null, data);
  },

  update: async (id: string, field: string, value: any) => {
    const match: Record<string, any> = {
      id,
      field
    };
    const data: any = {};
    data[field] = value;
    return api.PATCH('/api/task/update/:field/:id', match, data);
  },

  delete: async (id: string) => {
    return api.DELETE('/api/task/delete/:id', { id }, null);
  }

};

export default taskApi;
